package com.songlanyun.modules.marketing.groupbuy.model.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.songlanyun.common.drive.ValueObject;
import com.songlanyun.common.enums.MarketingConstant;
import com.songlanyun.common.utils.DateUtils;
import com.songlanyun.common.utils.custom.DateCustomUtils;
import com.songlanyun.common.utils.custom.MathUtils;
import com.songlanyun.common.validator.group.AddGroup;
import com.songlanyun.common.validator.group.UpdateGroup;
import com.songlanyun.modules.goods.entity.Goods;
import com.songlanyun.modules.marketing.groupbuy.entity.GroupBuyGoodsSku;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 秒杀活动商品表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-23 17:30:11
 */
@Data
public class GroupBuyActivityGoodsVO implements ValueObject {


    /**
     *
     */
    private Long id;

    //========商品=======
    /**
     * 商品id
     */
    private Long shopId;
    /**
     * 商品id
     */
    private Long goodsId;
    /**
     * 商品名称
     */
    private String title;
    /**
     * 商品图片
     */
    private String cover;
    /**
     * 主图视频
     */
    private String videoUrl;
    /**
     * 短标题
     */
    private String shortTitle;
    /**
     * 最低市场价
     */
    private BigDecimal minMarketPrice;
    /**
     * 最高市场价
     */
    private BigDecimal maxMarketPrice;
    //========商品=======

    /**
     * 拼团活动id
     */
    private Long groupBuyId;
    /**
     * 0固定折扣,1固定减价
     */
    private MarketingConstant.PriceType priceType;
    /**
     * 固定折扣、
     */
    private BigDecimal discount;

    public BigDecimal loadDiscount() {
        if (this.priceType.equals(MarketingConstant.PriceType.PRICE_FIXED_BY)) {
            this.discount = MathUtils.multiplyMulti(1,MathUtils.divideMulti(2,this.getMinPrice(), this.getMinSalePrice()),
                    new BigDecimal(10));
        }

        return this.discount;
    }
    /**
     * 固定减多少钱
     */
    private BigDecimal fixPrice;

    /**
     * 限购
     */
    private Integer limitBuyNum;
    /**
     *
     */
    private BigDecimal minPrice;
    /**
     *
     */
    private BigDecimal maxPrice;

    /**
     * 最低售价
     */
    private BigDecimal minSalePrice;
    /**
     * 最高售价
     */
    private BigDecimal maxSalePrice;
    /**
     * 活动价格区间
     */
    @TableField(exist = false)
    private String discountSection;

    public String getDiscountSection() {
        return this.minPrice + " - " + this.maxPrice;
    }

    /**
     * 投放的真实库存总数
     */
    private Integer realStockTotal;
    /**
     * 初始化销量（假销量）
     */
    private Integer initSaleNum;
    /**
     * 真实销量
     */
    private Integer realSaleNum;
    /**
     * 输出销量(初始化销量+真实销量)
     */
    private Integer resultSaleNum;
    /**
     * 成团总人数
     */
    private Integer groupPeopleNum;

    /**
     * 剩余库存(real_stock_total-result_sale_num)
     */
    private Integer residueStockTotal;

    /**
     * 活动开始时间
     */
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date startTime;
    /**
     * 活动结束时间
     */
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private Date endTime;

    private Long finishTime;//结束时间

    public Long getFinishTime() {
        Date endTime = this.getEndTime();//
        Date date = DateUtils.addDateDays(endTime, 1);
        return date.getTime()/1000;
    }

    private Integer sort;

    /**
     * 活动状态
     */
    @TableField(exist = false)
    private MarketingConstant.ActiveState activeState;

    /**
     * 活动状态
     *
     * @return
     */
    public MarketingConstant.ActiveState getActiveState() {

        return MarketingConstant.getGroupBuyActiveState(this.startTime, this.endTime);

    }
}
